﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Xml;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Text;
using Microsoft.Web.UI.WebControls;
using XMK.Tadong.Biz;

namespace XMK.Tadong.Web.TJ
{
    public partial class Data_FindobjectByKeyWordforobjectquery : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // 在此处放置用户代码以初始化页面
            Response.ClearContent();
            Response.ClearHeaders();
            Response.Clear();
            Response.ContentType = "text/xml";
            Response.Charset = "GB2312";
            Response.Expires = 0;
            Response.Cache.SetCacheability(HttpCacheability.NoCache);

            string wellname = "";
            string strSql = "";
            StringBuilder wellstring = new StringBuilder();
            string strKeyWord = Request.QueryString.Get("key");
            string type = Request.QueryString.Get("type");
            if (strKeyWord == null || strKeyWord == "")
                return;

            System.Xml.XmlDocument xdoc = new XmlDocument();

            //根据关键字模糊查询出所有二维工区
            if (type == "2darea")
            {
                strSql = "select distinct name from gis2dseismicarea where name like '%" + strKeyWord + "%'";
            }
            //根据关键字模糊查询出所有三维工区
            if (type == "3darea")
            {
                strSql = "select distinct name from gis3dseismicarea where name like '%" + strKeyWord + "%'";
            }
            //根据关键字模糊查询出所有二级构造
            if (type == "Structure")
            {
                strSql = "select distinct structurename as name from gisstructure where structurename like '%" + strKeyWord + "%'";
            }
            //根据关键字模糊查询出所有一级构造
            if (type == "Tectonic")
            {
                strSql = "select distinct name from gistectonic where name like '%" + strKeyWord + "%'";
            }
            //根据关键字模糊查询出所有井
            if (type == "Querywell")
            {
                string[] strKeyWords = strKeyWord.Split(',');
                int count = strKeyWords.Length;
                strSql = "select distinct jh as name from giswell where" + " " + "jh like '%" + strKeyWords[0] + "%'";
                for (int j = 1; j < count; j++)
                {
                    strSql = strSql + " " + " or jh like '%" + strKeyWords[j] + "%'";
                }
            }
            //根据井姓查询出所有井
            if (type == "well")
            {
                //20060622
                //Add By Joker
                //根据需要查询所有井号信息
                if (strKeyWord == "全部")
                {
                    strSql = "select distinct jh as name from giswell";
                }
                else
                {
                    strSql = "select distinct jh as name from giswell where substr(jh,0,1) =" + "'" + strKeyWord + "'";
                }
            }

            //JrscSoft.DataService.DataService dService = new JrscSoft.DataService.DataService();
            //连接数据库 
            try
            {
                //OracleDataReader reader = dService.GetDataReader(strSql);
                //while (reader.Read())
                //{
                YQCJDBLL bll = new YQCJDBLL();
                DataTable dt = bll.QueryData(strSql);
                for (int j = 0; j < dt.Rows.Count; j++)
                {
                    wellname = dt.Rows[j]["name"].ToString().Trim();
                    wellstring.Append(wellname);
                    wellstring.Append(",");
                }
                //}
                //reader.Close();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.Write(ex.Message);
            }


            //获取列表
            int i = wellstring.Length;
            if (i != 0)
            {
                wellstring = wellstring.Remove(i - 1, 1);
                //返回列表
                try
                {
                    XmlElement xeLayer = xdoc.CreateElement("welllist");
                    xdoc.AppendChild((XmlNode)xeLayer);
                    XmlElement elem = xdoc.CreateElement("wellS");
                    xeLayer.AppendChild((XmlNode)elem);
                    elem.SetAttribute("wells", wellstring.ToString());
                    elem.InnerText = wellstring.ToString();

                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.Write(ex.Message);
                }
            }
            if (xdoc != null)
            {
                xdoc.Save(Response.OutputStream);
            }
        
        }
    }
}